/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.interaction3d.assembly.convert.collada;

import org.interaction3d.assembly.convert.*;
import java.util.StringTokenizer;

/**
 *
 * @author micha
 */
public class Elements
{

    static public int[][][] triangles(String primitives, int count, int inputs)
    {
        final int triDiv = 3 * inputs;

        int[][][] triangles = new int[inputs][count][];
        int[][] tri = new int[inputs][3];
        int index = 0;

        StringTokenizer tokenizer = new StringTokenizer(primitives);
        while (tokenizer.hasMoreTokens())
        {
            {
                int attrIndex = index % inputs;
                int vIndex = (index / inputs) % 3;

                tri[attrIndex][vIndex] = Integer.parseInt(tokenizer.nextToken());
            }
            if (((index + 1) % triDiv) == 0)
            {
                int triIndex = index / triDiv;

                for (int attrIndex = 0; attrIndex < inputs; attrIndex++)
                {
                    int[] triAttr = tri[attrIndex];
                    triangles[attrIndex][triIndex] = new int[] {triAttr[0], triAttr[1], triAttr[2]};
                }
            }
            index++;
        }

        // <editor-fold defaultstate="collapsed" desc="debug prints">
        /*System.out.printf("Triangles: count='%d' attr='%d'\n", count, inputs);
        for (int i = 0; i < count; i++)
        {
            for (int j = 0; j < inputs; j++)
            {
                System.out.print(triangles[j][i].a + " ");
            }
            for (int j = 0; j < inputs; j++)
            {
                System.out.print(triangles[j][i].b + " ");
            }
            for (int j = 0; j < inputs; j++)
            {
                System.out.print(triangles[j][i].c + " ");
            }
        }
        System.out.println();*/
        // </editor-fold>

        return triangles;
    }

    static public double[][] coordinates(String data, int count, int stride, int offset)
    {
        double[][] vertexElements = new double[count][stride];

        StringTokenizer tokenizer = new StringTokenizer(data);

        int index = 0;
        while(index < offset) tokenizer.nextToken();

        index = 0;
        for(int i=0; i<vertexElements.length; i++) for(int j=0; j<vertexElements[i].length; j++)
        {
            vertexElements[i][j] = Double.parseDouble(tokenizer.nextToken());
        }
        return vertexElements;
    }
    
    private Elements() {}

    
}
